import { SendContextTpls } from './sendContextTpl';
let _SendContextTpls = SendContextTpls;
/**
 * 拷贝下面两行到 mock/index.js中,即可支持客户端虚拟数据、免服务端连接
 * import SendContextTplMock from './mdp/arc/send/sendContextTplMock';
 * SendContextTplMock.bootstrap(mock);
 */
export default {
  /**
   * mock bootstrap
   */
  bootstrap(mock) {    
  
    //获取列表 模糊查询、根据关键字查询
    mock.onGet('/mdp/arc/send/sendContextTpl/listKey').reply(config => {
      let params = config.params;
      let mockSendContextTpls = _SendContextTpls.filter(sendContextTpl => {
      	if(params.oaContext||params.oaContext==''){ if( sendContextTpl.oaContext.indexOf(params.oaContext)>=0) return true;}
      	if(params.mainTitle||params.mainTitle==''){ if( sendContextTpl.mainTitle.indexOf(params.mainTitle)>=0) return true;}
      	if(params.mainAbstract||params.mainAbstract==''){ if( sendContextTpl.mainAbstract.indexOf(params.mainAbstract)>=0) return true;}
      	if(params.shortMsgContext||params.shortMsgContext==''){ if( sendContextTpl.shortMsgContext.indexOf(params.shortMsgContext)>=0) return true;}
      	if(params.weixinContext||params.weixinContext==''){ if( sendContextTpl.weixinContext.indexOf(params.weixinContext)>=0) return true;}
      	if(params.otherContext||params.otherContext==''){ if( sendContextTpl.otherContext.indexOf(params.otherContext)>=0) return true;}
      	if(params.emailContext||params.emailContext==''){ if( sendContextTpl.emailContext.indexOf(params.emailContext)>=0) return true;}
      	if(params.id||params.id==''){ if( sendContextTpl.id.indexOf(params.id)>=0) return true;}
      	if(params.bizType||params.bizType==''){ if( sendContextTpl.bizType.indexOf(params.bizType)>=0) return true;}
        return false;
      });
      return new Promise((resolve, reject) => {
        setTimeout(() => {
          resolve([200, {
            data: mockSendContextTpls
          }]);
        }, 1000);
      });
    });
    
    

    //获取列表（分页/不分页）
    mock.onGet('/mdp/arc/send/sendContextTpl/list').reply(config => {
      let params = config.params;
      let mockSendContextTpls = _SendContextTpls.filter(sendContextTpl => {
      	var isTrue=false;
      	if(params.oaContext||params.oaContext==''){if(sendContextTpl.oaContext.indexOf(params.oaContext)>=0){isTrue=true;}else{isTrue=false;}}
      	if(params.mainTitle||params.mainTitle==''){if(sendContextTpl.mainTitle.indexOf(params.mainTitle)>=0){isTrue=true;}else{isTrue=false;}}
      	if(params.mainAbstract||params.mainAbstract==''){if(sendContextTpl.mainAbstract.indexOf(params.mainAbstract)>=0){isTrue=true;}else{isTrue=false;}}
      	if(params.shortMsgContext||params.shortMsgContext==''){if(sendContextTpl.shortMsgContext.indexOf(params.shortMsgContext)>=0){isTrue=true;}else{isTrue=false;}}
      	if(params.weixinContext||params.weixinContext==''){if(sendContextTpl.weixinContext.indexOf(params.weixinContext)>=0){isTrue=true;}else{isTrue=false;}}
      	if(params.otherContext||params.otherContext==''){if(sendContextTpl.otherContext.indexOf(params.otherContext)>=0){isTrue=true;}else{isTrue=false;}}
      	if(params.emailContext||params.emailContext==''){if(sendContextTpl.emailContext.indexOf(params.emailContext)>=0){isTrue=true;}else{isTrue=false;}}
      	if(params.id||params.id==''){if(sendContextTpl.id.indexOf(params.id)>=0){isTrue=true;}else{isTrue=false;}}
      	if(params.bizType||params.bizType==''){if(sendContextTpl.bizType.indexOf(params.bizType)>=0){isTrue=true;}else{isTrue=false;}}
      	return isTrue;
	  });
      if(!config.params.currentPage){ 
	      return new Promise((resolve, reject) => {
	        setTimeout(() => {
	          resolve([200, {
	            data: mockSendContextTpls
	          }]);
	        }, 1000);
	      });
      }
    
      let {pageSize,currentPage, total} = config.params;
      total = mockSendContextTpls.length;
      mockSendContextTpls = mockSendContextTpls.filter((sendContextTpl, index) => index < pageSize * currentPage && index >= pageSize * (currentPage - 1));
      return new Promise((resolve, reject) => {
        setTimeout(() => {
          resolve([200, {
            pageInfo: {
            	total:total
            },
            data: mockSendContextTpls,
            tips:{
            	isOk:true,
            	msg:'查询成功'
            }
          }]);
        }, 1000);
      });
    });

    //删除
    mock.onPost('/mdp/arc/send/sendContextTpl/del').reply(config => {
      var params = JSON.parse( config.data );
      let {  id  } = params;
      _SendContextTpls = _SendContextTpls.filter(sendContextTpl => sendContextTpl.id !== id);
      return new Promise((resolve, reject) => {
        setTimeout(() => {
          resolve([200, {
            tips:{
            	isOk:true,
            	msg:'删除成功'
            }
          }]);
        }, 500);
      });
    });

    //批量删除
    mock.onPost('/mdp/arc/send/sendContextTpl/batchDel').reply(config => {
      var params = JSON.parse( config.data );
      _SendContextTpls = _SendContextTpls.filter(sendContextTpl => !params.includes(sendContextTpl.id));
      return new Promise((resolve, reject) => {
        setTimeout(() => {
          resolve([200, {
           tips:{
            	isOk:true,
            	msg:'删除成功'
            }
          }]);
        }, 500);
      });
    });

    //编辑
    mock.onPost('/mdp/arc/send/sendContextTpl/edit').reply(config => {
      var params = JSON.parse( config.data );
      let { oaContext,mainTitle,mainAbstract,shortMsgContext,weixinContext,otherContext,emailContext,id,bizType } = params;
      _SendContextTpls.some(sendContextTpl => {
        if (sendContextTpl.id === id) {
			sendContextTpl.oaContext = oaContext;
			sendContextTpl.mainTitle = mainTitle;
			sendContextTpl.mainAbstract = mainAbstract;
			sendContextTpl.shortMsgContext = shortMsgContext;
			sendContextTpl.weixinContext = weixinContext;
			sendContextTpl.otherContext = otherContext;
			sendContextTpl.emailContext = emailContext;
			sendContextTpl.id = id;
			sendContextTpl.bizType = bizType
          return true;
        }
      });
      return new Promise((resolve, reject) => {
        setTimeout(() => {
          resolve([200, {
            tips:{
            	isOk:true,
            	msg:'编辑成功'
            }
          }]);
        }, 500);
      });
    });

    //新增
    mock.onPost('/mdp/arc/send/sendContextTpl/add').reply(config => {
      var params = JSON.parse( config.data );
      let { oaContext,mainTitle,mainAbstract,shortMsgContext,weixinContext,otherContext,emailContext,id,bizType } = params;
      _SendContextTpls.push({
		oaContext:oaContext,
		mainTitle:mainTitle,
		mainAbstract:mainAbstract,
		shortMsgContext:shortMsgContext,
		weixinContext:weixinContext,
		otherContext:otherContext,
		emailContext:emailContext,
		id:id,
		bizType:bizType
      });
      return new Promise((resolve, reject) => {
        setTimeout(() => {
          resolve([200, {
            tips:{
            	isOk:true,
            	msg:'新增成功'
            }
          }]);
        }, 500);
      });
    });

  }
};